package org.veridiandynamics.server.domain;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
 * Object representing a user who is a patient; stores all related information.
 *
 */
public class Patient extends User implements Serializable
{

	private Doctor myDoctor;
	private String pharmacy;
	private String insuranceCarrier;
	private String allergies;
	
//	private Set<TreatmentRecord> myTreatmentRecordList=new HashSet<TreatmentRecord>(0);
//	private Set<Appointment> myAppointments=new HashSet<Appointment>(0);

	private Set<TreatmentRecord> myTreatmentRecordList;
	private Set<Appointment> myAppointments;
	
	private static final long serialVersionUID = 10L;
	
	/**
	 * Constructor that takes in personal information about the user who is a patient.
	 * 
	 * @param username
	 * @param password
	 * @param personalInfo
	 * @param doctor
	 * @param recordSet
	 * @param pharmacy
	 * @param insuranceCarrier
	 * @param allergies
	 * @param myAppointments
	 */
	public Patient(String username, String password, Map<String, String> personalInfo, Doctor doctor, 
			Set<TreatmentRecord> recordSet, String pharmacy, String insuranceCarrier, String allergies,
			Set<Appointment> myAppointments)
	{
		myRoles = new HashSet<Roles>();
		myRoles.add(new Roles(RoleLookup.Role.PATIENT));
		
		setFirstName(personalInfo.get("first name"));
		setLastName(personalInfo.get("last name"));
		setMiddleName(personalInfo.get("middle name"));
		setStreetAddress(personalInfo.get("address"));
		setCity(personalInfo.get("city"));
		setState(personalInfo.get("state"));
		setZip(Integer.parseInt(personalInfo.get("zip")));
		setTelephone(personalInfo.get("telephone"));
		setCell(personalInfo.get("cell"));
		setEmail(personalInfo.get("email"));
		
		
		this.myDoctor = doctor;
		this.pharmacy = pharmacy;
		this.insuranceCarrier = insuranceCarrier;
		this.myTreatmentRecordList = recordSet;
		this.allergies = allergies; 
		this.myAppointments = myAppointments;
	}
	
	/**
	 * Constructor that takes in less than all applicable information about a patient.
	 * 
	 * @param username
	 * @param password
	 * @param personalInfo
	 * @param doctor
	 * @param pharmacy
	 * @param insuranceCarrier
	 * @param allergies
	 */
	public Patient(String username, String password, Map<String, String> personalInfo, Doctor doctor,
			String pharmacy, String insuranceCarrier, String allergies)
	{
		myRoles = new HashSet<Roles>();
		myRoles.add(new Roles(RoleLookup.Role.PATIENT));
		setFirstName(personalInfo.get("first name"));
		setLastName(personalInfo.get("last name"));
		setMiddleName(personalInfo.get("middle name"));
		setStreetAddress(personalInfo.get("address"));
		setCity(personalInfo.get("city"));
		setState(personalInfo.get("state"));
		setZip(Integer.parseInt(personalInfo.get("zip")));
		setTelephone(personalInfo.get("telephone"));
		setCell(personalInfo.get("cell"));
		setEmail(personalInfo.get("email"));
		
		this.myDoctor = doctor;
		this.pharmacy = pharmacy;
		this.insuranceCarrier = insuranceCarrier;
		this.allergies = allergies;
	}
	

	
	/**
	 * Default constructor lacking necessary information about patient.
	 */
	public Patient()
	{
		
	}
	

	
	/**
	 * Returns patient's doctor
	 * 
	 * @return object type Doctor
	 */
	public Doctor getMyDoctor() {
		return myDoctor;
	}

	/**
	 * Sets patient's doctor
	 * @param myDoctor object type Doctor
	 */
	public void setMyDoctor(Doctor myDoctor) {
		this.myDoctor = myDoctor;
	}

	
	/**
	 * Sets doctor. Duplicate method.
	 * @param doctor object type Doctor.
	 */
	public void setDoctor(Doctor doctor) {
		this.myDoctor = doctor;
	}
	
	/**
	 * Returns string containing name of pharmacy for patient.
	 * 
	 * @return object type String pharmacy
	 */
	public String getPharmacy() {
		return pharmacy;
	}



	/**
	 * Sets pharmacy for patient.
	 * @param pharmacy Object type string.
	 */
	public void setPharmacy(String pharmacy) {
		this.pharmacy = pharmacy;
	}



	/**
	 * Reutrns instance of patient's insurance carrier.
	 * 
	 * @return String insurance carrier.
	 */
	public String getInsuranceCarrier() {
		return insuranceCarrier;
	}



	/**
	 * Sets patient's insurance carrier.
	 * 
	 * @param insuranceCarrier
	 */
	public void setInsuranceCarrier(String insuranceCarrier) {
		this.insuranceCarrier = insuranceCarrier;
	}



	/**
	 * Gets allergies.
	 * @return String containing allergies.
	 */
	public String getAllergies() {
		return allergies;
	}



	/**
	 * Sets allergies.
	 * @param allergies String containing patient's allergies.
	 */
	public void setAllergies(String allergies) {
		this.allergies = allergies;
	}
	


	/**
	 * Gets appointments for instance of patient.
	 * @return Set of Appointment objects
	 */
	public Set<Appointment> getMyAppointments() {
		return myAppointments;
	}

	/**
	 * Sets appointments for instance of patient.
	 * 
	 * @param myAppointments Set of Appointment objects
	 */
	public void setMyAppointments(Set<Appointment> myAppointments) {
		this.myAppointments = myAppointments;
	}

	/**
	 * Gets Set of TreatmentRecord objects for patient
	 * @return Set TreatmentRecord objects
	 */
	public Set<TreatmentRecord> getMyTreatmentRecordList() {
		return myTreatmentRecordList;
	}

	/**
	 * Sets Set of TreatmentRecord objects for patient
	 * 
	 * @param myTreatmentRecordList Set TreatmentRecord objects
	 */
	public void setMyTreatmentRecordList(Set<TreatmentRecord> myTreatmentRecordList) {
		this.myTreatmentRecordList = myTreatmentRecordList;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		return getName();
	}
	
	/**
	 * Writes object.
	 * 
	 * @param outputStream
	 * @throws IOException
	 */
	private void writeObject(ObjectOutputStream outputStream) throws IOException {
		outputStream.defaultWriteObject();
	}
	
	/**
	 * Reads object.
	 * 
	 * @param inputStream
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */
	private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException {
		inputStream.defaultReadObject();
	}
}
